﻿using FamilyBook.Core.Entities;
using FamilyBook.Core.Repositories;

namespace FamilyBook.Core.Services
{
    public class SequenceService
    {
        private readonly IGeneralRepository<Sequence, SequenceType> _repository;

        public SequenceService(IGeneralRepository<Sequence, SequenceType> repository)
        {
            _repository = repository;
        }

        public void Reset(SequenceType sequenceType)
        {
            Sequence sequence = _repository.Read(sequenceType);
            sequence.Counter = 0;
            _repository.Update(sequence);
        }

        public int GetNextValue(SequenceType sequenceType)
        {
            Sequence sequence = _repository.Read(sequenceType);
            sequence.Counter++;
            _repository.Update(sequence);
            return sequence.Counter;
        }
    }
}
